package com.example.demojpa.service;

import com.example.demojpa.dao.CourseDao;
import com.example.demojpa.entity.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseService {

    @Autowired
    CourseDao courseDao;

    public Course saveCourse(Course course){
        Course save = courseDao.save(course);
        return save;
    }
    public boolean deleteCourse(Integer id){
        boolean b = courseDao.deleteCourseById(id);
        if (b) return true;
        else return false;
    }
    public Course update(Course course){
        return courseDao.save(course);
    }
    public Course findByName(String name){
        return courseDao.findCourseByName(name);
    }
    public List findAll(){
        return courseDao.findAll();
    }
    public List findByPage(Pageable pageable){
        return courseDao.findAll(pageable).getContent();
    }
}
